package edu.java.ishop.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;
import javax.inject.Named;
import javax.sql.DataSource;

import edu.java.ishop.dao.ProductCategoryDao;
import edu.java.ishop.model.ProductCategory;
@Named("databaseCategoryDao")
public class ProductCategoryDatabaseDao implements ProductCategoryDao {

	
	@Inject
	private DataSource dataSource;

	public ProductCategoryDatabaseDao() {
	}

	@Override
	public ProductCategory getById(long modelId) {
		return null;
	}

	@Override
	public List<ProductCategory> getAll() {
		List<ProductCategory> categories = new ArrayList<>();

		try (Connection connection = dataSource.getConnection();
				PreparedStatement stmt = connection
						.prepareStatement("select * from productcategory");
				ResultSet rs = stmt.executeQuery();) {
			while (rs.next()) {
				categories.add(new ProductCategory(rs.getLong(1), rs
						.getString(2)));
			}
		} catch (SQLException e) {
			throw new RuntimeException(e);
		}
		return categories;
	}

	@Override
	public boolean save(ProductCategory model) {
		return false;
	}

	@Override
	public void delete(long modelId) {

	}

	@Override
	public void delete(ProductCategory model) {

	}

}
